﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;

namespace WebServicesDome
{
    /// <summary>
    /// GetStudenServices 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class GetStudenServices : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public void GetStudent(string uid, string pwd)
        {
            DataTable dt = new DataTable("result");
            string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ToString();
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "Select * from Student";
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = conn;
                    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    {
                        sda.Fill(dt);
                    }
                }
            }
            string res = JsonConvert.SerializeObject(dt);

            Context.Response.ContentType = "text/html";
            Context.Response.ContentEncoding = Encoding.UTF8;
            Context.Response.Write(res);

        }


    }
}
